class Solution {
public:
    vector<int> findSubstring(string s, vector<string>& words) {
        unordered_map<string,int> hash1;
        
        for(auto& e: words)
        {
            hash1[e]++;
        }
        int len = words[0].size();//单词数组中的单词长度
        int m = words.size();
        vector<int> ret;
        for(int i=0;i<len;i++)//划分长度次
        {
            unordered_map<string,int> hash2;//维护窗口内的单词频次
            //count代表有效字符串的长度
            for(int left=i,right=i,count=0;right+len<=s.size();right+=len)
            {
                //进窗口，维护counnt
                string in = s.substr(right,len);
                hash2[in]++;
                if(hash2[in]<=hash1[in]) count++;
                //判断
                if(right-left+1>len*m)
                {
                    string out = s.substr(left,len);
                    if(hash2[out]<=hash1[out]) count--;
                    hash2[out]--;
                    left+=len;
                }
                if(count == m)
                    ret.push_back(left);
            }
        }
        return ret;
    }
};